package coupons

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/coupons"
    couponsReq "github.com/flipped-aurora/gin-vue-admin/server/model/coupons/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type PointsCouponsApi struct {}



// CreatePointsCoupons 创建pointsCoupons表
// @Tags PointsCoupons
// @Summary 创建pointsCoupons表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body coupons.PointsCoupons true "创建pointsCoupons表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /pointsCoupons/createPointsCoupons [post]
func (pointsCouponsApi *PointsCouponsApi) CreatePointsCoupons(c *gin.Context) {
	var pointsCoupons coupons.PointsCoupons
	err := c.ShouldBindJSON(&pointsCoupons)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = pointsCouponsService.CreatePointsCoupons(&pointsCoupons)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeletePointsCoupons 删除pointsCoupons表
// @Tags PointsCoupons
// @Summary 删除pointsCoupons表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body coupons.PointsCoupons true "删除pointsCoupons表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /pointsCoupons/deletePointsCoupons [delete]
func (pointsCouponsApi *PointsCouponsApi) DeletePointsCoupons(c *gin.Context) {
	id := c.Query("id")
	err := pointsCouponsService.DeletePointsCoupons(id)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeletePointsCouponsByIds 批量删除pointsCoupons表
// @Tags PointsCoupons
// @Summary 批量删除pointsCoupons表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /pointsCoupons/deletePointsCouponsByIds [delete]
func (pointsCouponsApi *PointsCouponsApi) DeletePointsCouponsByIds(c *gin.Context) {
	ids := c.QueryArray("ids[]")
	err := pointsCouponsService.DeletePointsCouponsByIds(ids)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdatePointsCoupons 更新pointsCoupons表
// @Tags PointsCoupons
// @Summary 更新pointsCoupons表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body coupons.PointsCoupons true "更新pointsCoupons表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /pointsCoupons/updatePointsCoupons [put]
func (pointsCouponsApi *PointsCouponsApi) UpdatePointsCoupons(c *gin.Context) {
	var pointsCoupons coupons.PointsCoupons
	err := c.ShouldBindJSON(&pointsCoupons)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = pointsCouponsService.UpdatePointsCoupons(pointsCoupons)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindPointsCoupons 用id查询pointsCoupons表
// @Tags PointsCoupons
// @Summary 用id查询pointsCoupons表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query coupons.PointsCoupons true "用id查询pointsCoupons表"
// @Success 200 {object} response.Response{data=coupons.PointsCoupons,msg=string} "查询成功"
// @Router /pointsCoupons/findPointsCoupons [get]
func (pointsCouponsApi *PointsCouponsApi) FindPointsCoupons(c *gin.Context) {
	id := c.Query("id")
	repointsCoupons, err := pointsCouponsService.GetPointsCoupons(id)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(repointsCoupons, c)
}
// GetPointsCouponsList 分页获取pointsCoupons表列表
// @Tags PointsCoupons
// @Summary 分页获取pointsCoupons表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query couponsReq.PointsCouponsSearch true "分页获取pointsCoupons表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /pointsCoupons/getPointsCouponsList [get]
func (pointsCouponsApi *PointsCouponsApi) GetPointsCouponsList(c *gin.Context) {
	var pageInfo couponsReq.PointsCouponsSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := pointsCouponsService.GetPointsCouponsInfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetPointsCouponsPublic 不需要鉴权的pointsCoupons表接口
// @Tags PointsCoupons
// @Summary 不需要鉴权的pointsCoupons表接口
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /pointsCoupons/getPointsCouponsPublic [get]
func (pointsCouponsApi *PointsCouponsApi) GetPointsCouponsPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    pointsCouponsService.GetPointsCouponsPublic()
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的pointsCoupons表接口信息",
    }, "获取成功", c)
}
